<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use App\Base\Annotation\Common;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ODM\Document(repositoryClass="App\Repository\SiteOilRepository")
 */
class SiteOil
{
    /**
     * @Common(cnName="#",editType="text",listType="text")
     * @ODM\Id(strategy="INCREMENT")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"list"})
     */
    private $id;

    /**
     * @Common(cnName="油号",editType="text",listType="text")
     * @ODM\Field( nullable=false)
     * @ORM\Column(type="string", length=255)
     * @Groups({"list"})
     */
    private $name;

    /**
     * @Common(cnName="枪位",editType="list",listType="text")
     * @ODM\ReferenceMany(targetDocument="App\Entity\SiteGun", mappedBy="oil")
     * @ORM\OneToMany(targetEntity="App\Entity\SiteGun", mappedBy="oil")
     * @Groups({"list"})
     */
    private $guns;

    /**
     * @Common(cnName="油站价格",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @ORM\Column(type="float", nullable=true)
     * @Groups({"list"})
     */
    private $priceOrg;

    /**
     * @Common(cnName="国标价",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @ORM\Column(type="float", nullable=true)
     * @Groups({"list"})
     */
    private $price;

    /**
     * @Common(cnName="活动价格",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @ORM\Column(type="float", nullable=true)
     * @Groups({"list"})
     */
    private $priceSale;

    /**
     * @Common(cnName="类型",editType="list",listType="text")
     * @ODM\ReferenceOne(targetDocument="App\Entity\SiteOilCategory", inversedBy="oils",reference=true)
     * @ORM\ManyToOne(targetEntity="App\Entity\SiteOilCategory", inversedBy="oils")
     * @ORM\JoinColumn(nullable=false)
     * @Groups({"list"})
     */
    private $category;

    public function __construct()
    {
        $this->guns = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return Collection|SiteGun[]
     */
    public function getGuns(): Collection
    {
        return $this->guns;
    }

    public function addGun(SiteGun $gun): self
    {
        if (!$this->guns->contains($gun)) {
            $this->guns[] = $gun;
            $gun->setOil($this);
        }

        return $this;
    }

    public function removeGun(SiteGun $gun): self
    {
        if ($this->guns->contains($gun)) {
            $this->guns->removeElement($gun);
            // set the owning side to null (unless already changed)
            if ($gun->getOil() === $this) {
                $gun->setOil(null);
            }
        }

        return $this;
    }

    public function getPriceOrg(): ?float
    {
        return $this->priceOrg;
    }

    public function setPriceOrg(?float $priceOrg): self
    {
        $this->priceOrg = $priceOrg;

        return $this;
    }

    public function getPrice(): ?float
    {
        return $this->price;
    }

    public function setPrice(?float $price): self
    {
        $this->price = $price;

        return $this;
    }

    public function getPriceSale(): ?float
    {
        return $this->priceSale;
    }

    public function setPriceSale(?float $priceSale): self
    {
        $this->priceSale = $priceSale;

        return $this;
    }

    public function getCategory(): ?SiteOilCategory
    {
        return $this->category;
    }

    public function setCategory(?SiteOilCategory $category): self
    {
        $this->category = $category;

        return $this;
    }
}
